<?php
class Model_grup extends CI_Model{
    
    function getAll(){
        $owner = $this->session->userdata('id_user');
        $query = $this->db->query("SELECT * FROM tb_group WHERE owner = $owner");
        return $query->result();
    }
    
    function submitGroup(){
        $data = array(
            'nama_group' => $this->input->post('name'),
            'keterangan' => $this->input->post('description'),
            'owner' => $this->session->userdata('id_user')
        );
        
        return $this->db->insert('tb_group', $data);
    }
    
    function getGroupById($id){
        $query = $this->db->query("SELECT * FROM tb_group WHERE id_group = $id");
        return $query->row();
    }
    
    function adding(){
        $data = array(
            'id_group' => $this->input->post('id_group'),
            'id_user' => $this->input->post('id_user')
        );
        return $this->db->insert('tb_member', $data);
    }
    
    function getMembers($id){
        $query = $this->db->query("SELECT m.id_group, m.id_user, u.nama, u.profpic FROM 
tb_member m,
tb_user u
WHERE m.id_user = u.id_user AND m.id_group = $id LIMIT 5");
        return $query->result();
    }
}
?>
